var http = require("http");
var url = require("url");
var qs = require('querystring');
var log = require('./logs').logs;

var start = function (ccd, routerplay) {
  http.createServer(function (request, response) {
    var lu = url.parse(request.url).pathname;
    var query = url.parse(request.url, true).query;
    if (query.file) {
      routerplay(ccd, lu, request, response, query);
    } else {
      routerplay(ccd, lu, request, response, qs);
    }
  }).listen(8888);
  log.info("服务器已启动,监听8888端口");
  log.info("        使用讲解      ");
  log.info("**************************************");
  log.info("接口地址:")
  log.info("读取文件 get => http://localhost:8888/index?file=文件的名字&path=文件夹名字&timeout=如有需要设置延迟的时间(单位: 秒)");
  log.info("读取文件 post => http://localhost:8888/postGetData  (参数同上(json格式))")
  log.info("写入文件 post => http://localhost:8888/file");
  log.info("写入文件的参数 JSON ");
  log.info("{path: 需要存储文件的位置(请提前创建好), name: 存储的文件名(系统自动创建), data: 文件内容(请转换为json字符串)}")
  log.info("接受form表单 get => http://localhost:8888/form");
  log.info("延迟2s响应 get => http://localhost:8888/time");
  log.info('==================================');
};

exports.start = start;
